{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-07-25 11:40:31 DEBUG     Using selector: SelectSelector\n",
      "2025-07-25 11:40:31 DEBUG     连接状态:True\n",
      "2025-07-25 11:40:31 DEBUG     over\n",
      "2025-07-25 11:40:31 INFO      <error id=-1, errorCode=503, errorMsg=已经订阅此帐户-55005490>\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<contractData reqId=931044, contract=<gj.ext.Contract.Contract object at 0x00007FAA0F2FEAD0>>\n",
      "931044\n",
      "<gj.ext.Contract.Contract object at 0x00007FAA0F2FEAD0>\n",
      "stock\n",
      "SZ\n",
      "000001\n",
      "平安银行\n",
      "19910403\n",
      "订阅帐号55005490成功\n"
     ]
    }
   ],
   "source": [
    "\n",
    "from time import sleep\n",
    "from gj.opt import gjConnection, message\n",
    "from gj.lib import logger\n",
    "\n",
    "mylog = logger.logger()\n",
    "\n",
    "\n",
    "def my_account_handler(msg):\n",
    "    print(msg)\n",
    "\n",
    "\n",
    "def my_tick_handler(msg):\n",
    "    print(msg)\n",
    "\n",
    "\n",
    "def error(msg):\n",
    "    mylog.info(msg)\n",
    "\n",
    "def historicalData(msg):\n",
    "    print(msg)\n",
    "    print(msg.reqId)\n",
    "    print(msg.contract)\n",
    "    print(msg.contract.instrument_type)\n",
    "    print(msg.contract.ExchangeID)\n",
    "    print(msg.contract.InstrumentID)\n",
    "    print(msg.contract.InstrumentName)\n",
    "    print(msg.contract.OpenDate)\n",
    "    \n",
    "    # print(msg.time)\n",
    "    # print(msg.open)\n",
    "    # print(msg.high)\n",
    "    # print(msg.low)\n",
    "    # print(msg.close)\n",
    "    # print(msg.volume)\n",
    "    # print(msg.amount)\n",
    "    # print(msg.preClose)\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "\n",
    "    # con.register(my_account_handler, 'UpdateAccountValue')\n",
    "    # con.register(my_tick_handler, message.tickSize, message.tickPrice)\n",
    "    import random\n",
    "\n",
    "    client_id = random.randint(1, 1000000)\n",
    "    \n",
    "    test=1\n",
    "    if test:\n",
    "        con = gjConnection(clientId=client_id)\n",
    "    else:\n",
    "        con = gjConnection(clientId=client_id,account='8886040520',path=r'S:\\国金证券QMT交易端\\userdata_mini')\n",
    "    \n",
    "    status = con.connect()\n",
    "    mymessage = getattr(message, 'error')\n",
    "    # his=getattr(message, 'liveData')\n",
    "    con.register(error, mymessage)\n",
    "    # con.register(historicalData,his)\n",
    "    con.register(historicalData,getattr(message, 'contractData'))\n",
    "    mylog.debug('连接状态:%s' % status)\n",
    "\n",
    "    mylog.debug('over')\n",
    "    paras = {\n",
    "             'stock_list': ['000001.SZ'],\n",
    "             'start_time': '20240301', 'end_time': '20240331', 'period': '1m','download':True,}\n",
    "    # con.reqSubscribeQuote(client_id, **paras)\n",
    "    con.reqContract(client_id, stock_code='000001.SZ')\n",
    "    # sleep(100)\n",
    "    con.reqSubscribeAccount()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gj.opt import gjConnection\n",
    "from gj.opt.receiver import Receiver\n",
    "from gj.opt.dispatcher import Dispatcher\n",
    "# conn=gjConnection()\n",
    "# d=Dispatcher()\n",
    "# # # print(conn.receiver.__class__.__dict__)\n",
    "# r=Receiver(d)\n",
    "# r.__dict__"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
